// 基类
class Animal {
  constructor(name) {
    this.name = name;
  }

  speak () {
    console.log(`${this.name} makes a noise.`);
  }
}

// 派生类
class Dog extends Animal {
  constructor(name, breed) {
    super(name); // 调用父类的构造函数
    this.breed = breed;
  }

  speak () {
    console.log(`${this.name} barks.`);
  }

  fetch () {
    console.log(`${this.name} is fetching the ball.`);
  }
}

// 示例用法
const dog = new Dog('Buddy', 'Golden Retriever');
dog.speak(); // 输出: Buddy barks.
dog.fetch(); // 输出: Buddy is fetching the ball.
